﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Cosmetic.DataAccess;
using Cosmetic.DataEntity;
using System.Configuration;
using System.Data.Linq.SqlClient;
using System.Data.SqlClient;
using System.Data;

namespace Cosmetic.Logic
{
    public class FirstCategoryPictureManager
    {
        /// <summary>
        /// 查找一级类别的图片。
        /// 如果传入为空的参数，刚查找所有的。
        /// </summary>
        /// <returns></returns>
        public static DataSet GetAllProduct(string ID)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = string.Empty;
                if (string.IsNullOrEmpty(ID))
                {
                    cmdStr = "select * from [dbo].[FirstCategory] ";
                }
                else
                {
                    cmdStr = "select * from [dbo].[FirstCategory] where [ID] ='" + ID + "'";
                }
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds;
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 得到指定的一级类广告图片。
        /// </summary>
        /// <param name="categoryID"></param>
        /// <returns></returns>
        public static DataSet GetTheCategoryPicture(string categoryID)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = string.Empty;

                cmdStr = "select * from [dbo].[FirstCategory] where [FirstCategoryID] ='" + categoryID + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds;
            }
            finally
            {
                con.Close();
            }
        }

        public static DataSet GetTheCategoryPictures(int  categoryID)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = string.Empty;

                cmdStr = "select * from [dbo].[FirstCategory] where [FirstCategoryID] ='" + categoryID + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds;
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 插入一条类别图片信息。
        /// </summary>
        /// <param name="categoryID"></param>
        /// <param name="name"></param>
        /// <param name="ImgPathF"></param>
        /// <param name="ImgPathS"></param>
        public static void InsertCagetoryProduct(string categoryID, string name, string ImgPathF, string ImgPathS,string other,string other2)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = string.Empty;

                cmdStr = "INSERT INTO [dbo].[FirstCategory]  ([ID] ,[FirstCategoryID] ,[ImgPathF]  ,[ImgPathS] ,[CategoryName]  ,[Other], [Other2])  VALUES (newid() , '" + categoryID + "' ,'" + ImgPathF + "'  ,'" + ImgPathS + "' ,'" + name + "' ,'"+other+"','"+other2+"')";

                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 删除一条信息。
        /// </summary>
        /// <param name="ID"></param>
        public static void DeleteCagetoryProduct(string ID)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "delete [dbo].[FirstCategory] where [ID] ='" + ID + "'";

                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 更新类别图片信息。
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="categoryID"></param>
        /// <param name="name"></param>
        /// <param name="ImgPathF"></param>
        /// <param name="ImgPathS"></param>
        public static void UpdateCategoryProduct(string ID, string categoryID, string name, string ImgPathF, string ImgPathS, string other, string other2)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();

                string cmdStr = "UPDATE [dbo].[FirstCategory]   SET [FirstCategoryID] ='" + categoryID + "'  ,[ImgPathF] = '" + ImgPathF + "'  ,[ImgPathS] = '" + ImgPathS + "'  ,[CategoryName] = '" + name + "',[Other]='" + other + "',[Other2]='" + other2 + "' WHERE ID='" + ID + "'";

                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

    }//end class
}
